// Package sysin
// @Link  https://github.com/bufanyun/hotgo
// @Copyright  Copyright (c) 2024 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License  https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.15.7
package sysin

import (
	"context"
	"hotgo/internal/consts"
	"hotgo/internal/model/entity"
	"hotgo/internal/model/input/form"
	"hotgo/utility/validate"

	"github.com/gogf/gf/v2/errors/gerror"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gtime"
)

// EpOrderUpdateFields 修改订单字段过滤
type EpOrderUpdateFields struct {
	Ordernum        string `json:"ordernum"        dc:"订单号"`
	Recycler        int64  `json:"recycler"        dc:"服务天使"`
	Category        string `json:"category"        dc:"分类"`
	Sort            string `json:"sort"            dc:"排序"`
	Uid             int64  `json:"uid"             dc:"用户ID"`
	Name            string `json:"name"            dc:"姓名"`
	Phone           string `json:"phone"           dc:"电话"`
	Price           string `json:"price"           dc:"金额"`
	Weight          string `json:"weight"          dc:"预估重量"`
	TotalMoney      string `json:"totalMoney"      dc:"总金额"`
	Appointmenttime string `json:"appointmenttime" dc:"预约时间"`
	Status          int    `json:"status"          dc:"状态"`
	Address         string `json:"address"         dc:"地址"`
	Delreason       string `json:"delreason"       dc:"取消原因"`
	Delcontent      string `json:"delcontent"      dc:"取消备注"`
}

// EpOrderInsertFields 新增订单字段过滤
type EpOrderInsertFields struct {
	Ordernum        string `json:"ordernum"        dc:"订单号"`
	Recycler        int64  `json:"recycler"        dc:"服务天使"`
	Category        string `json:"category"        dc:"分类"`
	Sort            string `json:"sort"            dc:"排序"`
	Uid             int64  `json:"uid"             dc:"用户ID"`
	Name            string `json:"name"            dc:"姓名"`
	Phone           string `json:"phone"           dc:"电话"`
	Price           string `json:"price"           dc:"金额"`
	Weight          string `json:"weight"          dc:"预估重量"`
	TotalMoney      string `json:"totalMoney"      dc:"总金额"`
	Appointmenttime string `json:"appointmenttime" dc:"预约时间"`
	Status          int    `json:"status"          dc:"状态"`
	Address         string `json:"address"         dc:"地址"`
	Delreason       string `json:"delreason"       dc:"取消原因"`
	Delcontent      string `json:"delcontent"      dc:"取消备注"`
}

// EpOrderEditInp 修改/新增订单
type EpOrderEditInp struct {
	entity.EpOrder
}

func (in *EpOrderEditInp) Filter(ctx context.Context) (err error) {
	// 验证订单号
	if err := g.Validator().Rules("required").Data(in.Ordernum).Messages("订单号不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证服务天使
	if err := g.Validator().Rules("required").Data(in.Recycler).Messages("服务天使不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证分类
	if err := g.Validator().Rules("required").Data(in.Category).Messages("分类不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证排序
	if err := g.Validator().Rules("required").Data(in.Sort).Messages("排序不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证用户ID
	if err := g.Validator().Rules("required").Data(in.Uid).Messages("用户ID不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证姓名
	if err := g.Validator().Rules("required").Data(in.Name).Messages("姓名不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证电话
	if err := g.Validator().Rules("required").Data(in.Phone).Messages("电话不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证金额
	if err := g.Validator().Rules("regex:(^[0-9]{1,10}$)|(^[0-9]{1,10}[\\.]{1}[0-9]{1,2}$)").Data(in.Price).Messages("金额最多允许输入10位整数及2位小数").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证预估重量
	if err := g.Validator().Rules("required").Data(in.Weight).Messages("预估重量不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证总金额
	if err := g.Validator().Rules("required").Data(in.TotalMoney).Messages("总金额不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证预约时间
	if err := g.Validator().Rules("required").Data(in.Appointmenttime).Messages("预约时间不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证状态
	if err := g.Validator().Rules("required").Data(in.Status).Messages("状态不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证地址
	if err := g.Validator().Rules("required").Data(in.Address).Messages("地址不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证取消原因
	if err := g.Validator().Rules("required").Data(in.Delreason).Messages("取消原因不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证取消备注
	if err := g.Validator().Rules("required").Data(in.Delcontent).Messages("取消备注不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	return
}

type EpOrderEditModel struct{}

// EpOrderDeleteInp 删除订单
type EpOrderDeleteInp struct {
	Id interface{} `json:"id" v:"required#ID不能为空" dc:"ID"`
}

func (in *EpOrderDeleteInp) Filter(ctx context.Context) (err error) {
	return
}

type EpOrderDeleteModel struct{}

// EpOrderViewInp 获取指定订单信息
type EpOrderViewInp struct {
	Id int64 `json:"id" v:"required#ID不能为空" dc:"ID"`
}

func (in *EpOrderViewInp) Filter(ctx context.Context) (err error) {
	return
}

type EpOrderViewModel struct {
	entity.EpOrder
}

// EpOrderListInp 获取订单列表
type EpOrderListInp struct {
	form.PageReq
	Id        int64         `json:"id"        dc:"ID"`
	Status    int           `json:"status"    dc:"状态"`
	CreatedAt []*gtime.Time `json:"createdAt" dc:"created_at"`
}

func (in *EpOrderListInp) Filter(ctx context.Context) (err error) {
	return
}

type EpOrderListModel struct {
	Id              int64  `json:"id"              dc:"ID"`
	Ordernum        string `json:"ordernum"        dc:"订单号"`
	Recycler        int64  `json:"recycler"        dc:"服务天使"`
	Category        string `json:"category"        dc:"分类"`
	Sort            string `json:"sort"            dc:"排序"`
	Uid             int64  `json:"uid"             dc:"用户ID"`
	Name            string `json:"name"            dc:"姓名"`
	Phone           string `json:"phone"           dc:"电话"`
	Price           string `json:"price"           dc:"金额"`
	Weight          string `json:"weight"          dc:"预估重量"`
	TotalMoney      string `json:"totalMoney"      dc:"总金额"`
	Appointmenttime string `json:"appointmenttime" dc:"预约时间"`
	Status          int    `json:"status"          dc:"状态"`
}

// EpOrderExportModel 导出订单
type EpOrderExportModel struct {
	Id              int64       `json:"id"              dc:"ID"`
	Ordernum        string      `json:"ordernum"        dc:"订单号"`
	Recycler        int64       `json:"recycler"        dc:"服务天使"`
	Category        string      `json:"category"        dc:"分类"`
	Sort            string      `json:"sort"            dc:"排序"`
	Uid             int64       `json:"uid"             dc:"用户ID"`
	Name            string      `json:"name"            dc:"姓名"`
	Phone           string      `json:"phone"           dc:"电话"`
	Price           string      `json:"price"           dc:"金额"`
	Weight          string      `json:"weight"          dc:"预估重量"`
	TotalMoney      string      `json:"totalMoney"      dc:"总金额"`
	Appointmenttime string      `json:"appointmenttime" dc:"预约时间"`
	Status          int         `json:"status"          dc:"状态"`
	Address         string      `json:"address"         dc:"地址"`
	Delreason       string      `json:"delreason"       dc:"取消原因"`
	Delcontent      string      `json:"delcontent"      dc:"取消备注"`
	CreatedAt       *gtime.Time `json:"createdAt"       dc:"created_at"`
	UpdatedAt       *gtime.Time `json:"updatedAt"       dc:"updated_at"`
}

// EpOrderMaxSortInp 获取订单最大排序
type EpOrderMaxSortInp struct{}

func (in *EpOrderMaxSortInp) Filter(ctx context.Context) (err error) {
	return
}

type EpOrderMaxSortModel struct {
	Sort int `json:"sort"  description:"排序"`
}

// EpOrderStatusInp 更新订单状态
type EpOrderStatusInp struct {
	Id     int64 `json:"id" v:"required#ID不能为空" dc:"ID"`
	Status int   `json:"status" dc:"状态"`
}

func (in *EpOrderStatusInp) Filter(ctx context.Context) (err error) {
	if in.Id <= 0 {
		err = gerror.New("ID不能为空")
		return
	}

	if in.Status <= 0 {
		err = gerror.New("状态不能为空")
		return
	}

	if !validate.InSlice(consts.StatusSlice, in.Status) {
		err = gerror.New("状态不正确")
		return
	}
	return
}

type EpOrderStatusModel struct{}